package com.kelvin.paopao.module.main.date.dateperson;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.kelvin.kelvinlib.utils.LogUtil;
import com.kelvin.paopao.R;
import com.kelvin.paopao.adapter.DatePersonAdapter;
import com.kelvin.paopao.api.responseBean.DatePersonModel;
import com.kelvin.paopao.injector.components.DaggerDatePersonComponent;
import com.kelvin.paopao.injector.modules.DatePersonModule;
import com.kelvin.paopao.module.base.BaseActivity;
import com.kelvin.paopao.module.person.detail.PersonDetailActivity;
import com.kelvin.paopao.widgets.CustomToolbar;

import org.apache.commons.logging.Log;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;

/**
 * Created by Administrator on 2017/5/16.
 */

public class DatePersonActivity extends BaseActivity<IDatePersonPresenter> implements IDatePersonView {
    @BindView(R.id.custom_toolbar)
    CustomToolbar customToolbar;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;

    private LinearLayoutManager manager;
    private int id;

    @Inject
    DatePersonAdapter datePersonAdapter;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_date_person;
    }

    @Override
    protected void initInjector() {
        DaggerDatePersonComponent.builder().datePersonModule(new DatePersonModule(this))
                .build().inject(this);
    }

    @Override
    protected void initViews() {
        customToolbar.showBackIcon(this);
        id = getIntent().getIntExtra("id", 0);
        manager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(manager);
        datePersonAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                switch (view.getId()) {
                    case R.id.iv_touxiang:
                        PersonDetailActivity.launch(DatePersonActivity.this,
                                ((DatePersonModel) adapter.getData().get(position)).getUser_no());
                        break;
                    case R.id.tv_date_him:
                        if (datePersonAdapter.isCanCheck()) {
                            mPresenter.confirm(String.valueOf(id),
                                    ((DatePersonModel) adapter.getData().get(position)).getUser_no());
                        }
                        break;
                }
            }
        });
        recyclerView.setAdapter(datePersonAdapter);
    }

    @Override
    protected void updateViews(boolean isRefresh) {
        mPresenter.getData(id);
    }

    /**
     * 進入申請邀約人的界面
     *
     * @param context
     */
    public static void launch(Context context, int id) {
        Intent intent = new Intent(context, DatePersonActivity.class);
        intent.putExtra("id", id);
        context.startActivity(intent);
    }

    @Override
    public void loadData(List<DatePersonModel> models) {
        datePersonAdapter.setNewData(models);
    }

    @Override
    public void loadEmpty() {
        View noDataView = LayoutInflater.from(this).inflate(R.layout.view_no_data,
                (ViewGroup) recyclerView.getParent(), false);
        datePersonAdapter.setEmptyView(noDataView);
    }

    @Override
    public void loadCheck(boolean isCanCheck) {
        datePersonAdapter.setCanCheck(isCanCheck);
        datePersonAdapter.notifyDataSetChanged();
    }
}
